<!-- src/views/knowledge/Manage.vue -->
<template>
  <div class="knowledge-manage">
    <div class="toolbar">
      <h2>知识管理</h2>
      <el-button type="primary" @click="addKnowledge">新增知识</el-button>
    </div>
    <el-table :data="knowledgeList" border stripe>
      <el-table-column prop="id" label="ID" width="80" />
      <el-table-column prop="title" label="标题" />
      <el-table-column prop="author" label="作者" />
      <el-table-column prop="date" label="创建日期" />
      <el-table-column label="操作" width="180">
        <template #default="scope">
          <el-button size="small" @click="edit(scope.row)">编辑</el-button>
          <el-button size="small" type="danger" @click="remove(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import {ElMessage, ElMessageBox} from "element-plus";

const knowledgeList = ref([
  { id: 1, title: 'Vue 3 入门指南', author: '张三', date: '2023-10-01' },
  { id: 2, title: 'React Hooks 最佳实践', author: '李四', date: '2023-10-15' }
])

const addKnowledge = () => {
  ElMessage.info('新增知识')
}
const edit = (row) => {
  ElMessage.info(`编辑: ${row.title}`)
}
const remove = (row) => {
  ElMessageBox.confirm(`确定删除 "${row.title}"?`, '警告', { type: 'warning' })
      .then(() => {
        knowledgeList.value = knowledgeList.value.filter(k => k.id !== row.id)
        ElMessage.success('删除成功')
      })
}
</script>

<style scoped>
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
</style>
